package main

import (
	"fmt"
	"log"
	"net"
)

func main() {
	conn, err := net.Dial("tcp", "127.0.0.1:7878")
	if err != nil {
		log.Fatalf("Failed to connect to server: %v", err)
	}
	defer conn.Close()

	msg := "Hello, gnet echo server!"
	_, err = conn.Write([]byte(msg))
	if err != nil {
		log.Fatalf("Failed to write to server: %v", err)
	}

	buf := make([]byte, len(msg))
	_, err = conn.Read(buf)
	if err != nil {
		log.Fatalf("Failed to read from server: %v", err)
	}

	fmt.Printf("Received from server: %s\n", buf)
}
